﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace VerficationsWPF.HWControls
{
    /// <summary>
    /// ButifulDialog.xaml 的交互逻辑
    /// </summary>
    public partial class ConfirmDialog : Window
    {
        public ConfirmDialog()
        {
            InitializeComponent();
            WindowDragger wd = new WindowDragger(topDock);
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        /// <summary>
        /// 以指定控件为中心进行显示。
        /// </summary>
        /// <param name="element"></param>
        public bool? ShowAt(FrameworkElement element)
        {
            if (double.IsNaN(element.ActualWidth) || double.IsNaN(element.ActualHeight))
            {
                WindowStartupLocation = WindowStartupLocation.CenterScreen;
                return ShowDialog();
            }
            else
            {
                WindowStartupLocation = WindowStartupLocation.Manual;
                var leftTop = element.PointToScreen(new Point(0, 0));
                
                this.Left = leftTop.X + (element.ActualWidth - this.Width) / 2;
                this.Top = leftTop.Y + (element.ActualHeight - this.Height) / 2;
                return ShowDialog();
            } 
        }

        private void Label_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Close();
        }
    }
}
